<?php use_helper('Form')?>
<div class="panel"><?php echo form_tag('reportes/index')?> <?php echo input_date_tag ('fecha',$fecha1, array('rich'=>true))?>
hasta <?php echo input_date_tag('fecha2',$fecha2, array('rich'=>true))?>
<?php echo submit_tag('Cambiar')?>
</form>
<?php $masVendidos = ArticuloPeer::getTopMasVendidos()?>
<table class="table-datos">
	<thead>
		<tr>
			<th># Ventas</th>
			<th># Art. Vendidos</th>
			<th>Total Ventas</th>
			<th>Articulo Más Vendido</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td><?php echo $numVentas?></td>
			<td><?php echo $numArticulos?></td>
			<td><?php echo $totalVenta?></td>
			<td><?php echo $masVendidos[0]['codigo']?></td>
		</tr>
	</tbody>
</table>
</div>
<div class="tops">
<table class="table-top">
	<caption>Top Más Vendidos</caption>
	<thead>
		<tr>
			<th>Clave</th>
			<th>Nombre</th>
			<th>Cantidad</th>
		</tr>
	</thead>
	<tbody>

	<?php foreach($masVendidos as $TopVendidos):?>
		<tr>
			<td><?php echo $TopVendidos['codigo']?></td>
			<td><?php echo $TopVendidos['nombre']?></td>
			<td><?php echo $TopVendidos['cant']?></td>
		</tr>
		<?php endforeach;?>
	</tbody>
</table>
<table class="table-top">
	<caption>Top Clientes</caption>
	<thead>
		<tr>
			<th>Email</th>
			<th>Total Compras</th>
			<th>Cantidad</th>
		</tr>
	</thead>
	<tbody>
	<?php foreach($topClientes as $clientes):?>
		<tr>
			<td><?php echo $clientes['compradoremail']?></td>
			<td><?php echo $clientes['suma']?></td>
			<td><?php echo $clientes['cliente_id']?></td>
		</tr>
		<?php endforeach;?>
	</tbody>
</table>

		<?php $articulos = $masVendidos;?> <?php $datos = "";?> <?php $max = 0;?>
		<?php foreach(ArticuloPeer::getTopMasVendidos() as $articulos):?> <?php  $datos .= "{$articulos['cant']},";?>
		<?php $max = $articulos['cant']>$max ? $articulos['cant'] : $max?> <?php endforeach;?>
		<?php $datos = trim($datos,',')?></div>

<div class="tops">
<h3>Registro de Ventas</h3>
<table class="table-top">
	<thead>
		<tr>
			<th>Venta ID</th>
			<th>Transaccion</th>
			<th>Comprador</th>
			<th>Status</th>
			<th>Descuento</th>
			<th>Total</th>
		</tr>
	</thead>
	<tbody>
	<?php foreach($ventasList as $venta):?>
		<tr>
			<td><?php echo $venta->getVentaId()?></td>
			<td><?php echo $venta->getVenta()->getTransaccionid()?></td>
			<td><?php echo $venta->getVenta()->getCompradoremail()?></td>
			<td><?php echo $venta->getVenta()->getCompradorstatus()?>-<?php echo $venta->getVenta()->getPagostatus()?></td>
			     
			<td><?php echo $venta->getVenta()->getDescuento()?></td>			
			<td><?php echo $venta->getVenta()->getTotal()?></td>
		</tr>
		<?php endforeach;?>
	</tbody>
	<tfoot>
		<tr>
			<td></td>
		</tr>
	</tfoot>
</table>
</div>


<div class="tops">
<h3>Registro de Articulos Vendidos</h3>
<table class="table-top">
	<thead>
		<tr>
			<th>Codigo</th>
			<th>Nombre</th>
			<th>Cantidad</th>
			<th>Precio</th>
			<th>Existencia</th>
		</tr>
	</thead>
	<tbody>
	<?php foreach($articuloList as $articulo):?>
		<tr>
			<td><?php echo $articulo['CODIGO']?></td>
			<td><?php echo $articulo['NOMBRE']?></td>
			<td><?php echo $articulo['cant']?></td>
			<td><?php echo $articulo['PRECIO']?></td>
			<td><?php echo $articulo['EXISTENCIA']?></td>
		</tr>
		<?php endforeach;?>
	</tbody>
</table>
</div>
